package com.gmail.huxiaowi.cblog.util;

/**
 * 分页信息类
 * Class PageInfo
 * 
 * @author  huxw
 * @version $Revision:1.0.0, $Date:2010-5-6 下午05:26:18$
 */
public class PageInfo {

    public PageInfo(int totalRecords, int perPageRecords) {
        super();
        this.totalRecords = totalRecords;
        this.perPageRecords = perPageRecords;
        getTotalPages();
    }

    /**
     * @return the totalRecords
     */
    public int getTotalRecords() {
        return totalRecords;
    }
    /**
     * @param totalRecords the totalRecords to set
     */
    public void setTotalRecords(int totalRecords) {
        this.totalRecords = totalRecords;
    }
    /**
     * @return the totalPages
     */
    public int getTotalPages() {
        totalPages = ((totalRecords % perPageRecords) == 0) 
                        ? (totalRecords / perPageRecords)
                        : (totalRecords / perPageRecords + 1);
        return totalPages;
    }
    /**
     * @param totalPages the totalPages to set
     */
    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }
    /**
     * @return the perPageRecords
     */
    public int getPerPageRecords() {
        return perPageRecords;
    }
    /**
     * @param perPageRecords the perPageRecords to set
     */
    public void setPerPageRecords(int perPageRecords) {
        this.perPageRecords = perPageRecords;
    }
    /**
     * @return the localPageNo
     */
    public int getLocalPageNo() {
        return localPageNo;
    }
    /**
     * @param localPageNo the localPageNo to set
     */
    public void setLocalPageNo(int localPageNo) {
        
        if (localPageNo <= 0 || localPageNo > this.totalPages) {
            localPageNo = 1;
        }
        
        this.localPageNo = localPageNo;
    }

    /**
     * @return the startRecord
     */
    public int getStartRecord() {
        startRecord = (localPageNo - 1) * perPageRecords;
        return startRecord;
    }

    /**
     * @param startRecord the startRecord to set
     */
    public void setStartRecord(int startRecord) {
        this.startRecord = startRecord;
    }

    /**
     * @return the endRecord
     */
    public int getEndRecord() {
        endRecord = localPageNo * perPageRecords;
        return endRecord;
    }

    /**
     * @param endRecord the endRecord to set
     */
    public void setEndRecord(int endRecord) {
        this.endRecord = endRecord;
    }

    private int totalRecords;
    private int totalPages;
    private int perPageRecords;
    private int localPageNo;
    private int startRecord;
    private int endRecord;
}
